home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / c01lab4.zip / LRMRDR / LRM_CHAP.ZIP / CHAP11.DOC < prev    next >
Text File  |  1992-04-21  |  35KB  |  816 lines

  1. >                               11. Exceptions
  2.  
  3.  
  4. This  chapter  defines  the  facilities  for  dealing  with errors or other
  5. exceptional  situations  that  arise  during  program  execution.   Such  a
  6. situation  is  called  an  exception.   To raise an exception is to abandon
  7. normal program execution so as to draw  attention  to  the  fact  that  the
  8. corresponding situation has arisen.  Executing some actions, in response to
  9. the arising of an exception, is called handling the exception.
  10.  
  11.  
  12. An  exception  declaration  declares a name for an exception.  An exception
  13. can be raised by a  raise  statement,  or  it  can  be  raised  by  another
  14. statement  or  operation  that propagates the exception.  When an exception
  15. arises, control can be transferred to a user-provided exception handler  at
  16. the  end  of  a  block statement or at the end of the body of a subprogram,
  17. package, or task unit.
  18.  
  19.  
  20. References:  block statement 5.6, error situation  1.6,  exception  handler
  21. 11.2,  name  4.1,  package  body  7.1,  propagation  of an exception 11.4.1
  22. 11.4.2, raise statement 11.3, subprogram body 6.3, task body 9.1
  23.  
  24. > 11.1  Exception Declarations
  25.  
  26.  
  27. An exception declaration declares a name for an exception.  The name of  an
  28. exception  can  only  be  used in raise statements, exception handlers, and
  29. renaming declarations.
  30.  
  31.  
  32.     exception_declaration ::= identifier_list : exception;
  33.  
  34.  
  35. An exception declaration  with  several  identifiers  is  equivalent  to  a
  36. sequence  of  single  exception  declarations, as explained in section 3.2.
  37. Each  single  exception  declaration  declares  a  name  for  a   different
  38. exception.   In  particular,  if  a  generic  unit  includes  an  exception
  39. declaration, the exception declarations implicitly generated  by  different
  40. instantiations  of  the  generic unit refer to distinct exceptions (but all
  41. have  the  same  identifier).   The  particular  exception  denoted  by  an
  42. exception name is determined at compilation time and is the same regardless
  43. of  how  many  times the exception declaration is elaborated.  Hence, if an
  44. exception declaration occurs in a recursive subprogram, the exception  name
  45. denotes the same exception for all invocations of the recursive subprogram.
  46.  
  47.  
  48. The  following  exceptions are predefined in the language;  they are raised
  49. when the situations described are detected.
  50.  
  51.  
  52. CONSTRAINT_ERROR  This  exception  is  raised  in  any  of  the   following
  53.                   situations:    upon   an   attempt  to  violate  a  range
  54.                   constraint,  an  index  constraint,  or  a   discriminant
  55.                   constraint;   upon  an  attempt to use a record component
  56.                   that does not exist for the current discriminant  values;
  57.                   and  upon  an  attempt  to  use  a selected component, an
  58.                   indexed component, a slice, or an attribute, of an object
  59.                   designated by an access value, if  the  object  does  not
  60.                   exist because the access value is null.
  61.  
  62.  
  63.    NUMERIC_ERROR  This exception is raised by the execution of a predefined
  64.                   numeric  operation  that  cannot deliver a correct result
  65.                   (within the declared  accuracy  for  real  types);   this
  66.                   includes   the   case  where  an  implementation  uses  a
  67.                   predefined   numeric   operation   for   the   execution,
  68.                   evaluation,  or elaboration of some construct.  The rules
  69.                   given in section 4.5.7  define  the  cases  in  which  an
  70.                   implementation  is  not  required to raise this exception
  71.                   when such an error situation arises;   see  also  section
  72.                   11.6.
  73.  
  74.  
  75.    PROGRAM_ERROR  This exception is  raised  upon  an  attempt  to  call  a
  76.                   subprogram, to activate a task, or to elaborate a generic
  77.                   instantiation,  if the body of the corresponding unit has
  78.                   not yet been elaborated.  This exception is  also  raised
  79.                   if the end of a function is reached (see 6.5);  or during
  80.                   the  execution of a selective wait that has no else part,
  81.                   if this execution determines that  all  alternatives  are
  82.                   closed   (see   9.7.1).    Finally,   depending   on  the
  83.                   implementation, this exception  may  be  raised  upon  an
  84.                   attempt  to  execute an action that is erroneous, and for
  85.                   incorrect order dependences (see 1.6).
  86.  
  87.  
  88.    STORAGE_ERROR  This  exception  is  raised  in  any  of  the   following
  89.                   situations:  when the dynamic storage allocated to a task
  90.                   is  exceeded;   during the evaluation of an allocator, if
  91.                   the space  available  for  the  collection  of  allocated
  92.                   objects  is  exhausted;   or  during the elaboration of a
  93.                   declarative item, or during the execution of a subprogram
  94.                   call, if storage is not sufficient.
  95.  
  96.  
  97.    TASKING_ERROR  This exception is raised  when  exceptions  arise  during
  98.                   intertask communication (see 9 and 11.5).
  99.  
  100. Note:
  101.  
  102.  
  103. The  situations described above can arise without raising the corresponding
  104. exceptions, if the pragma SUPPRESS has been used to give permission to omit
  105. the corresponding checks (see 11.7).
  106.  
  107.  
  108. Examples of user-defined exception declarations:
  109.  
  110.     SINGULAR : exception;
  111.     ERROR    : exception;
  112.     OVERFLOW, UNDERFLOW : exception;
  113.  
  114.  
  115. References:  access value 3.8, collection 3.8, declaration  3.1,  exception
  116. 11,  exception handler 11.2, generic body 12.2, generic instantiation 12.3,
  117. generic unit 12, identifier 2.3, implicit declaration  12.3,  instantiation
  118. 12.3,  name  4.1, object 3.2, raise statement 11.3, real type 3.5.6, record
  119. component 3.7, return statement 5.8, subprogram  6,  subprogram  body  6.3,
  120. task 9, task body 9.1
  121.  
  122.  
  123. Constraint_error exception contexts:  aggregate 4.3.1 4.3.2, allocator 4.8,
  124. assignment  statement  5.2 5.2.1, constraint 3.3.2, discrete type attribute
  125. 3.5.5, discriminant constraint  3.7.2,  elaboration  of  a  generic  formal
  126. parameter  12.3.1  12.3.2  12.3.4  12.3.5,  entry index 9.5, exponentiating
  127. operator 4.5.6, index constraint 3.6.1, indexed  component  4.1.1,  logical
  128. operator  4.5.1, null access value 3.8, object declaration 3.2.1, parameter
  129. association 6.4.1, qualified expression 4.7, range constraint 3.5, selected
  130. component 4.1.3, slice 4.1.2, subtype indication 3.3.2, type conversion 4.6
  131.  
  132.  
  133. Numeric_error exception contexts:  discrete type attribute 3.5.5,  implicit
  134. conversion  3.5.4 3.5.6 4.6, numeric operation 3.5.5 3.5.8 3.5.10, operator
  135. of a numeric type 4.5 4.5.7
  136.  
  137.  
  138. Program_error  exception  contexts:   collection  3.8,   elaboration   3.9,
  139. elaboration  check  3.9  7.3  9.3  12.2,  erroneous  1.6,  incorrect  order
  140. dependence 1.6, leaving a function 6.5, selective wait 9.7.1
  141.  
  142.  
  143. Storage_error exception contexts:  allocator 4.8
  144.  
  145.  
  146. Tasking error exception contexts:  abort statement  9.10,  entry  call  9.5
  147. 9.7.2 9.7.3, exceptions during task communication 11.5, task activation 9.3
  148.  
  149. > 11.2  Exception Handlers
  150.  
  151.  
  152. The  response  to  one  or  more  exceptions  is  specified by an exception
  153. handler.
  154.  
  155.  
  156.     exception_handler ::=
  157.        when exception_choice {| exception_choice} =>
  158.           sequence_of_statements
  159.  
  160.     exception_choice ::= exception_name | others
  161.  
  162.  
  163. An exception handler occurs in a construct that is either a block statement
  164. or the body of a subprogram, package, task unit, or generic unit.   Such  a
  165. construct  will be called a frame in this chapter.  In each case the syntax
  166. of a frame that has exception handlers includes the following part:
  167.  
  168.  
  169.     begin
  170.         sequence_of_statements
  171.     exception
  172.         exception_handler
  173.        {exception_handler}
  174.     end
  175.  
  176.  
  177. The exceptions denoted by the exception names given as exception choices of
  178. a frame must all be distinct.  The exception choice others is only  allowed
  179. for the last exce